﻿using System.Collections.Generic;

namespace Auktionshuset___Server
{
    public class UserMonitor
    {
        private static readonly Dictionary<string, User> Users = new Dictionary<string, User>();
        private static readonly object SyncRoot = new object();

        public User Get(string username)
        {
            lock (SyncRoot)
            {
                return Users[username];
            }
        }

        public bool Exists(string username)
        {
            lock (SyncRoot)
            {
                return Users.ContainsKey(username);
            }
        }

        public void Add(User user)
        {
            if (Exists(user.Username)) return;

            lock (SyncRoot)
            {
                Users[user.Username] = user;
            }
        }
    }
}
